function assignCustomItems()
--------------------------------------------------------------------------------------------------------------
--PLACE CUSTOM ASSIGNMENTS BELOW HERE
--------------------------------------------------------------------------------------------------------------




--------------------------------------------------------------------------------------------------------------
--PLACE CUSTOM ASSIGNMENTS ABOVE HERE
--------------------------------------------------------------------------------------------------------------
end

--------------------------------------------------------------------------------------------------------------

function PlayerUpdate(idx)
	local as = gSportsRNA
	local player = as:GetTable("wvPlayer", idx)
	local state = as:GetTable("wvState")
	
	db.player[idx].lightType = as:GetInt(state, "wvAttribStadLighting")
	db.player[idx].stadiumID = as:GetInt(state, "wvAttribStadID")
	local weather = math.min( 1, as:GetInt(state, "wvAttribStadWeather" ) )
	
	db.player[idx].wet = weather
	
	db.player[idx].playerassetid = as:GetInt(player, "playerassetid") 
	db.player[idx].teamid = as:GetInt(player, "teamid") 
	db.player[idx].teamside = as:GetInt(player, "teamside") 
	db.player[idx].isgoalie = as:GetInt(player, "goalie") 
	
	db.player[idx].kit = as:GetInt(player, "kit") 
	db.player[idx].kitType = as:GetInt(player, "kitType") 
	db.player[idx].kitYear = as:GetInt(player, "kitYear") 

	local kitNumber = as:GetInt(player, "kitNumber") 
	db.player[idx].kitNumberTens = math.floor ( kitNumber / 10 )
	db.player[idx].kitNumberUnits = math.floor ( math.fmod(kitNumber, 10) )

	db.player[idx].kitNameFont = as:GetInt(player, "kitNameFont")
	db.player[idx].kitNumberFont = as:GetInt(player, "kitNumberFont")
	db.player[idx].kitNumberColor = as:GetInt(player, "kitNumberColor")
	db.player[idx].kitNameColor = as:GetInt(player, "kitNameColor")
	
	db.player[idx].shortsNumberFont = as:GetInt(player, "shortsNumberFont")
	db.player[idx].shortsNumberColor = as:GetInt(player, "shortsNumberColor")
	db.player[idx].jerseyNameVisible = as:GetInt(player, "jerseyNameVisible")
	db.player[idx].jerseyNameLayout = as:GetInt(player, "jerseyNameLayout")
	
	db.player[idx].head = as:GetInt(player, "playerHead") 
	db.player[idx].headClass = as:GetInt(player, "playerHeadClass") 
	
	db.player[idx].jerseyCollarType = as:GetInt(player, "jerseyCollarType") 
	db.player[idx].jerseySleeveLength = as:GetInt(player, "jerseySleeveLength") 
	db.player[idx].jerseyArmBand = as:GetInt(player, "jerseyArmBand") 
	db.player[idx].jerseyTucked = as:GetInt(player, "jerseyTucked") 
	db.player[idx].jerseyBagginess = 0 --as:GetInt(player, "jerseyBagginess") 
	db.player[idx].socklength = as:GetInt(player, "socklength")
	db.player[idx].shortstyle = as:GetInt(player, "shortstyle")
	
	db.player[idx].bodySkinToneType = as:GetInt(player, "playerBodySkinToneType")
	db.player[idx].headSkinToneType = as:GetInt(player, "playerHeadSkinToneType")
	db.player[idx].headSkinType = as:GetInt(player, "playerHeadSkinType")
	db.player[idx].playerBodySkinColor = as:GetInt(player, "playerBodySkinColor")
	db.player[idx].faceGenSkinToneType = as:GetInt(player, "faceGenSkinToneType")
	
	db.player[idx].shoeType = as:GetInt(player, "shoeType")
	db.player[idx].shoeColor = as:GetInt(player, "shoeColor")
	
	db.player[idx].faceType = as:GetInt(player, "faceType")
	db.player[idx].faceProxyHeadClass = as:GetInt(player, "faceProxyHeadClass")
	-- Faceproxyheadclass should never be greater than one including createplayer
	if (db.player[idx].faceProxyHeadClass == 2) then
		db.player[idx].faceProxyHeadClass = 1
	end
	
	db.player[idx].faceSideBurn = as:GetInt(player, "faceSideBurn")
	db.player[idx].facialHairColor = as:GetInt(player, "facialHairColor")
	db.player[idx].facialHairType = as:GetInt(player, "facialHairType")
	db.player[idx].eyebrow = as:GetInt(player, "eyebrow")
	
	db.player[idx].isVirtualPro = as:GetInt(player, "isVirtualPro")
	db.player[idx].isCreatePlayer = as:GetInt(player, "isCreatePlayer")
	db.player[idx].faceTexExtension = "rx3"
	
	db.player[idx].isCreationZone = as:GetInt(player, "isFCZ")
	db.player[idx].hasCzCrestImage = as:GetInt(player, "hasCzCrestImage")
	db.player[idx].crestAssetId = as:GetInt(player, "crestAssetId")
	db.player[idx].forceLowResBNM = as:GetInt(player, "forceLowResBNM")
	db.player[idx].forcePowerOfTwoBNM = as:GetInt(player, "forcePowerOfTwoBNM")
	db.player[idx].forceunderarm = as:GetInt(player, "forceunderarm")
	db.player[idx].forceundershorts = as:GetInt(player, "forceundershorts")
	db.player[idx].forceunderneck = as:GetInt(player, "forceunderneck")

	db.player[idx].sponsorAssetId = as:GetInt(player, "sponsorAssetId")
	db.player[idx].hotspotJerseySponsorL = as:GetFloat(player, "hotspotJerseySponsorL")
	db.player[idx].hotspotJerseySponsorT = as:GetFloat(player, "hotspotJerseySponsorT")
	db.player[idx].hotspotJerseySponsorR = as:GetFloat(player, "hotspotJerseySponsorR")
	db.player[idx].hotspotJerseySponsorB = as:GetFloat(player, "hotspotJerseySponsorB")
	
	db.player[idx].kitColourJerseyPri = as:GetInt(player, "kitColourJerseyPri")
	db.player[idx].kitColourJerseySec = as:GetInt(player, "kitColourJerseySec")
	db.player[idx].kitColourJerseyTer = as:GetInt(player, "kitColourJerseyTer")

	db.player[idx].kitColourShortPri = as:GetInt(player, "kitColourShortPri")
	db.player[idx].kitColourShortSec = as:GetInt(player, "kitColourShortSec")
	db.player[idx].kitColourShortTer = as:GetInt(player, "kitColourShortTer")

	db.player[idx].kitColourSocksPri = as:GetInt(player, "kitColourSocksPri")
	db.player[idx].kitColourSocksSec = as:GetInt(player, "kitColourSocksSec")
	db.player[idx].kitColourSocksTer = as:GetInt(player, "kitColourSocksTer")

	db.player[idx].sponsorcolour = as:GetInt(player, "sponsorcolour")

	db.player[idx].crestTexName = "crest_cm"
	
	if (db.player[idx].isCreationZone == 1 and db.player[idx].hasCzCrestImage > 0) then
		db.player[idx].crestTexName = "png";
	end

	if (db.player[idx].isVirtualPro == 1) then
		db.player[idx].faceTexExtension = "dds"
	end
	
	db.player[idx].faceTypeFallback = 0
	db.player[idx].headFallback = 0
	db.player[idx].faceSideBurnFallback = db.player[idx].faceSideBurn
	db.player[idx].facialHairColorFallback = db.player[idx].facialHairColor
	db.player[idx].facialHairTypeFallback = db.player[idx].facialHairType
	db.player[idx].headSkinTypeFallback = db.player[idx].headSkinType
	db.player[idx].headSkinToneTypeFallback = db.player[idx].headSkinToneType
	
	if(db.player[idx].headSkinToneTypeFallback == 1 or db.player[idx].headSkinToneTypeFallback == 3 or db.player[idx].headSkinToneTypeFallback == 7) then
		db.player[idx].headSkinToneTypeFallback = db.player[idx].headSkinToneTypeFallback + 1
	end
	
	-- If create player then we need the create player head
	-- head_{id}_{headClass}.rx2
	-- {id} == 0 is create player
	-- {id} == 1 is create player copy
	-- {id} == 2 is facegen head
	-- {id} == 3 is facegen head copy
 	if (db.player[idx].isCreatePlayer == 1) then
		db.player[idx].headClass = 2
		db.player[idx].faceProxyHeadClass = 1
		
		if (db.player[idx].isVirtualPro == 1) then
			db.player[idx].faceSideBurn = 0
			db.player[idx].facialHairColor = 0
			db.player[idx].facialHairType = 0
			db.player[idx].headSkinType = 0
			db.player[idx].headSkinToneType = 0
			
		end
		
	end
	
	
	db.player[idx].eyeColor = as:GetInt(player, "eyeColor")
	db.player[idx].hair = as:GetInt(player, "hair")
	db.player[idx].hairColor = as:GetInt(player, "hairColor") 
	

	--FACE
	db.player[idx].headClass = getPlayerFace(db.player[idx].playerassetid,db.player[idx].headClass)
	db.player[idx].faceProxyHeadClass = getPlayerFace(db.player[idx].playerassetid,db.player[idx].faceProxyHeadClass)

	if (db.player[idx].headClass == 0) then
	
		local playerassetid = db.player[idx].playerassetid
		
		db.player[idx].head = playerassetid 
		db.player[idx].eyeColor = playerassetid

		db.player[idx].eyebrow = 0
		db.player[idx].faceType = playerassetid
		db.player[idx].faceSideBurn = 0
		db.player[idx].facialHairColor = 0
		db.player[idx].facialHairType = 0
		db.player[idx].headSkinType = 0
		db.player[idx].headSkinToneType = 0

		db.player[idx].hair = playerassetid
		db.player[idx].hairColor = 0
	else
		if(db.player[idx].headSkinToneType == 1 or db.player[idx].headSkinToneType == 3 or db.player[idx].headSkinToneType == 7) then
			db.player[idx].headSkinToneType = db.player[idx].headSkinToneType + 1
		end
		--tmp
		-- db.player[idx].hairColorIdx = db.player[idx].hairColor
		-- db.player[idx].hairColor = 0	
	end
	
	
-- Seasonal Assets --
	-- These exist only here and not in the code:
	local seasonal = as:GetInt(player, "seasonaljersey")
	db.player[idx].armLength = db.player[idx].jerseySleeveLength
	db.player[idx].underneck = -1 
	db.player[idx].underarms = -1 
	db.player[idx].undershorts = -1 
	
	local weather2 = as:GetInt(state, "wvAttribStadWeather" )
	
	--GET ACCESSORY WEATHER
	local winterAcc = getWinterAccessoriesWeather(weather2)
	
	--GET PLAYER WINTER ACCESSORIES
	local seasonal = getWinterAccessories(db.player[idx].playerassetid,seasonal)
	
	--SLEEVE LENGTH
	db.player[idx].jerseySleeveLength = getSleeveLength(db.player[idx].playerassetid,db.player[idx].jerseySleeveLength)
	
	if (winterAcc or db.player[idx].isVirtualPro == 1 or db.player[idx].isCreatePlayer == 1) then
	--if (weather > 0 or db.player[idx].isVirtualPro == 1 or db.player[idx].isCreatePlayer == 1) then
       -- Long Sleeves no underarmor stuff
		if (seasonal == 1) then
			db.player[idx].jerseySleeveLength  = 1
			db.player[idx].underneck = -1
			db.player[idx].underarms = -1
			db.player[idx].armLength = 1
		-- Long Sleeves and just underarmor neck
		elseif (seasonal == 2) then
			db.player[idx].jerseySleeveLength = 1
			db.player[idx].underneck = 0    
			db.player[idx].underarms = -1
			db.player[idx].armLength = 1
		-- Short sleeves with underarmor arms no neck
		elseif (seasonal == 3) then
			db.player[idx].jerseySleeveLength  = 0
			db.player[idx].underneck = -1
			db.player[idx].underarms = 0
			db.player[idx].armLength = 1
		-- Short sleeves with underarmor neck and arms
		elseif (seasonal == 4) then
			db.player[idx].jerseySleeveLength  = 0
			db.player[idx].underneck = 0
			db.player[idx].underarms = 0
			db.player[idx].armLength = 1
		end
		
		db.player[idx].undershorts = 0 
		
  	end
	-- end of seasonal assets
	
	-- check if we need to force underwear for injuries
	if ( db.player[idx].forceunderarm == 1 ) then
		db.player[idx].jerseySleeveLength  = 0
		db.player[idx].underarms = 0
		db.player[idx].armLength = 1
	end
	
	if ( db.player[idx].forceundershorts == 1 ) then
		db.player[idx].undershorts = 0 
	end
	
	if ( db.player[idx].forceunderneck == 1 ) then
		db.player[idx].underneck = 0 
	end

	-- Goalie long pants, turn off necessary assets.
	if( db.player[idx].shortstyle == 1 ) then
		db.player[idx].socklength = -1
		db.player[idx].undershorts = -1
	end
	
	db.player[idx].useTextureComposition = as:GetInt(player, "useTextureComposition")
	
	
	
	
	
	assignCustomItems()
	
	
	--GK KIT SPEC
	if (db.player[idx].kitType == 2) then
	db.player[idx].kit = getSpecificGKKit(db.player[idx].teamid,db.player[idx].kit)
	end
	
	--ARENA PLAYER KIT
	if (idx == 0) then
	if (arenaModePlayerKitTeam ~= -1) then
	db.player[idx].kit = arenaModePlayerKitTeam
	db.player[idx].kitType = arenaModePlayerKitType
	end
	end

	--ARENA GK KIT
	if (idx == 1) then
	if (arenaModeGKKitTeam ~= -1) then
	db.player[idx].kit = arenaModeGKKitTeam
	db.player[idx].kitType = arenaModeGKKitType
	end
	end
	
	
	--FOR MATCHES #1
	if (idx > 1) then
	
	--GK KITS
	if (db.player[idx].kitType == 2) then
	local stadium = as:GetTable("wvStadium", 1)
	
	db.stadium[1].homeKitTeamID = as:GetInt(stadium, "homeKitTeamID" )
	db.stadium[1].awayKitTeamID = as:GetInt(stadium, "awayKitTeamID" )
	db.stadium[1].homeKitTypeID = as:GetInt(stadium, "homeKitTypeID" )
	db.stadium[1].awayKitTypeID = as:GetInt(stadium, "awayKitTypeID" )
	
	if (db.player[idx].kit == db.stadium[1].homeKitTeamID) then
	db.player[idx].kitType = getGKKit(db.player[idx].kit,db.stadium[1].homeKitTypeID,db.stadium[1].homeKitTeamID,db.stadium[1].awayKitTeamID,db.player[idx].kitType)
	else
	db.player[idx].kitType = getGKKit(db.player[idx].kit,db.stadium[1].awayKitTypeID,db.stadium[1].homeKitTeamID,db.stadium[1].awayKitTeamID,db.player[idx].kitType)
	end
	
	else
	--NON GK KIT
	
	--SPECIFIC MATCH KIT
	db.player[idx].kitType = getGameKit(db.player[idx].kit,db.stadium[1].homeKitTeamID,db.stadium[1].awayKitTeamID,db.player[idx].kitType)
	end
	
	
	end
	--FOR MATCHES #2
	--if (idx > 1) then
	local wipe3d = as:GetTable("wvWipe", 1)
	db.wipe3d[1].leagueID = as:GetInt(wipe3d, "leagueID")
	
	db.wipe3d[1].leagueID = getTournamentGraphics(db.wipe3d[1].leagueID)
	
	if (idx < 2) then
	db.wipe3d[1].leagueID = 0
	end
	
	
	
	
	
	--KIT DETAILS
	db.player[idx].kitNameFont = getKitNameFont(db.player[idx].kit,db.player[idx].kitType,db.player[idx].kitNameFont,db.wipe3d[1].leagueID)
	db.player[idx].kitNumberFont = getKitNumberSet(db.player[idx].kit,db.player[idx].kitType,db.player[idx].kitNumberFont,db.wipe3d[1].leagueID)
	db.player[idx].kitNumberColor = getKitNumberColourShirt(db.player[idx].kit,db.player[idx].kitType,db.player[idx].kitNumberColor,db.wipe3d[1].leagueID)
	db.player[idx].kitNameColor = getKitNameColour(db.player[idx].kit,db.player[idx].kitType,db.player[idx].kitNameColor,db.wipe3d[1].leagueID)
	db.player[idx].shortsNumberFont = getKitNumberSet(db.player[idx].kit,db.player[idx].kitType,db.player[idx].shortsNumberFont,db.wipe3d[1].leagueID)
	db.player[idx].shortsNumberColor = getKitNumberColourShort(db.player[idx].kit,db.player[idx].kitType,db.player[idx].shortsNumberColor,db.wipe3d[1].leagueID)
	--db.player[idx].jerseyNameLayout = as:GetInt(player, "jerseyNameLayout")
	db.player[idx].jerseyCollarType = getKitCollar(db.player[idx].kit,db.player[idx].kitType,db.player[idx].jerseyCollarType,db.wipe3d[1].leagueID)
	
	db.player[idx].jerseyNameLayout = getKitNameCurve(db.player[idx].kit,db.player[idx].kitType,db.player[idx].jerseyNameLayout,db.wipe3d[1].leagueID)
	
	
	--FOR MATCHES #2
	if (idx > 1) then
	-- local wipe3d = as:GetTable("wvWipe", 1)
	-- db.wipe3d[1].leagueID = as:GetInt(wipe3d, "leagueID")
	
	-- db.wipe3d[1].leagueID = getTournamentGraphics(db.wipe3d[1].leagueID)
	
	

	--REF KITS
	if (db.player[idx].kitType == 5) then
	
	initRefKits()
	
	if (db.player[idx].kit > 6010) then
	db.player[idx].kit = db.player[idx].kit - 10
	end
	
	local stadium = as:GetTable("wvStadium", 1)
	db.stadium[1].homeKitTeamID = as:GetInt(stadium, "homeKitTeamID" )
	
	db.player[idx].kitYear = getTournamentRefereeKits(db.wipe3d[1].leagueID,db.player[idx].kitYear,db.stadium[1].homeKitTeamID)
	end
	
	
	
	
	
	
	--PLAYER KITS
	if (db.player[idx].kitType ~= 5) then
		
	db.player[idx].kitYear = getTournamentPlayerKits(db.player[idx].kit,db.wipe3d[1].leagueID,db.player[idx].kitYear)
	
	if (db.player[idx].kitYear ~= 0) then
	db.player[idx].kitNumberFont = getTournamentPlayerKitsNumber(db.player[idx].kit,db.wipe3d[1].leagueID,db.player[idx].kitNumberFont)
	db.player[idx].kitNameFont = getTournamentPlayerKitsName(db.player[idx].kit,db.wipe3d[1].leagueID,db.player[idx].kitNameFont)
	db.player[idx].shortsNumberFont = getTournamentPlayerKitsNumber(db.player[idx].kit,db.wipe3d[1].leagueID,db.player[idx].shortsNumberFont)
	end
	
	end
	
	
	
	
	
	end


	
	
	--BOOTS
	db.player[idx].shoeType = getPlayerBoot(db.player[idx].playerassetid,db.player[idx].shoeType)
	if (db.player[idx].shoeType > 0) then
	db.player[idx].shoeColor = 0
	end
	
	--GK PANTS
	db.player[idx].shortstyle = getGKPants(db.player[idx].playerassetid,db.player[idx].shortstyle)
	db.player[idx].shortstyleset = getTeamGKPants(db.player[idx].kit,0)
	
	--SKIN TONE
	db.player[idx].bodySkinToneType = getPlayerPlayerSkinTone(db.player[idx].playerassetid,db.player[idx].bodySkinToneType)
	
	--JERSEY TUCK
	db.player[idx].jerseyTucked = getJerseyTuck(db.player[idx].playerassetid,db.player[idx].jerseyTucked)
	
	--SOCK HEIGHT
	db.player[idx].socklength = getSockHeight(db.player[idx].playerassetid,db.player[idx].socklength)
	
	

	
	
	
	
	
	
		
end

---------------------------------------------------------------------------------------------------
-- Get hair color for generic hair recoloring 
function GetHairColorARGB(idx)
	hairColourList = { 0x00edac57, 0x000e0e0d, 0x00a07741, 0x001f160e, 
                       0x00ffd286, 0x006e4d2b, 0x003b2816, 0x00782c08, 
                       0x00c8c9cf, 0x00525355, 0x00345a34, 0x00263f67 }

	local clr = 0x00FF0000
	if (db.player[idx].headClass > 0) then
		clr = hairColourList[db.player[idx].hairColor + 1]
		if (clr == nil) then
			clr = 0x00FF0000
		end
	else
		clr = 0x00808080
	end
	return clr
end

---------------------------------------------------------------------------------------------------
function EASWMorphFile(idx)
	if (db.player[idx].isVirtualPro == 1) then
		return string.format("data/easw/deltas_%d.easwmorph", db.player[idx].faceType) --12366)
	else
		return "dummyasset.easwmorph"
	end
end

---------------------------------------------------------------------------------------------------
function GetHeadAndHairAssetType(idx)
	if (db.player[idx].isCreatePlayer == 1) then
		return "cloneasset"
	else
		return ""
	end
end

---------------------------------------------------------------------------------------------------
function MorphFile(idx)
	if (db.player[idx].isCreatePlayer == 1 and db.player[idx].isVirtualPro == 0) then
		return "data/sceneassets/createplayer/head_0_2_0_1_morphtargets.rx3"
	else
		return "dummyasset.rx3"
	end
end

---------------------------------------------------------------------------------------------------
function PlayerAssetShadow(player, lod)
	local gr = gRenderables
	gr:AddAsset(player, lod, "shadow", "data/sceneassets/body/playershadow_4_1_0.rx3")
	gr:CreateMaterial(player, lod, "shadow", "missingShader.fx")
end

---------------------------------------------------------------------------------------------------
function GetCrestAsset(idx)
	if (db.player[idx].isCreationZone == 1) then
		if (db.player[idx].hasCzCrestImage > 0) then
			-- // The "\\" is so that the mounted image can be found properly by Apt
			return "data\\ugc/cz_crest/${db.player[?].crestAssetId}.png;data/ugc/cz_crest/1.png"
		else
			return "data/sceneassets/crest/crest_${db.player[?].crestAssetId}.rx3"
		end
	else
		return "data/sceneassets/kit/kit_${db.player[?].kit}_${db.player[?].kitType}_${db.player[?].kitYear}.rx3"
	end

end

---------------------------------------------------------------------------------------------------
function GetSkinTone(idx, lod)
	local useLight = false
	if (db.player[idx].isVirtualPro == 1) then
		-- // 0 is light, 1 is dark
		useLight = ( db.player[idx].faceGenSkinToneType == 0 )
	else
		useLight = ( db.player[idx].bodySkinToneType < 5 )
	end
	
	if ( useLight ) then
		return ( lod == 0 ) and "skin_light" or "skin_lod_light"
	else
		return ( lod == 0 ) and "skin_dark" or "skin_lod_dark"
	end
end

---------------------------------------------------------------------------------------------------
function GetFaceTone(idx, lod)
	local useLight = false
	if (db.player[idx].isVirtualPro == 1) then
		-- // 0 is light, 1 is dark
		useLight = ( db.player[idx].faceGenSkinToneType == 0 )
	else
		useLight = ( db.player[idx].bodySkinToneType < 5 )
	end
	
	if ( useLight ) then
		return ( lod == 0 ) and "face_light" or "face_lod_light"
	else
		return ( lod == 0 ) and "face_dark" or "face_lod_dark"
	end
end

---------------------------------------------------------------------------------------------------
function PlayerAssetHighLod(player, lod)
	local gr = gRenderables
	
    -- GEO's
	gr:AddAsset(player, lod, "jersey", "data/sceneassets/body/jersey_${db.player[?].jerseyCollarType}_${db.player[?].jerseySleeveLength}_${db.player[?].jerseyArmBand}_${db.player[?].jerseyTucked}_${db.player[?].jerseyBagginess}.rx3")
	gr:AddAsset(player, lod, "arms", "data/sceneassets/body/arms_${db.player[?].armLength}.rx3")
	gr:AddAsset(player, lod, "shorts", "data/sceneassets/body/shorts_${db.player[?].shortstyle}.rx3")
	gr:AddAsset(player, lod, "shoes",  "data/sceneassets/shoe/shoe_${db.player[?].shoeType}.rx3")
	gr:AddAsset(player, lod, "socks", "data/sceneassets/body/sock_${db.player[?].socklength}.rx3")
	gr:AddAsset(player, lod, "legs",  "data/sceneassets/body/legs_${db.player[?].socklength}.rx3")
	gr:AddAssetEx(player, lod, "${GetHeadAndHairAssetType(?)}", "hair1", "data/sceneassets/hair/hair_${db.player[?].hair}_${db.player[?].faceProxyHeadClass}_0.rx3")
	gr:AddAssetEx(player, lod, "${GetHeadAndHairAssetType(?)}", "hair2", "data/sceneassets/hair/hair_${db.player[?].hair}_${db.player[?].faceProxyHeadClass}_0.rx3")
	gr:AddAssetEx(player, lod, "${GetHeadAndHairAssetType(?)}", "head",  "data/sceneassets/heads/head_${db.player[?].head}_${db.player[?].headClass}.rx3")
    -- Point the eyes to the same asset the head uses, whether it being cloned or not.
	gr:AddAssetEx(player, lod, "fromasset", "eyes", "head")
	-- non volume texture normalMap for socks
	gr:AddAsset(player, lod, "sockbnmlod", "data/sceneassets/kit/shorts_${db.player[?].shortstyle}_bnm_lod.rx3")
	
	-- Add the morph files
	
	local priority = 0	-- default priority
	local temporary = 1	-- mark as temporary asset
	gr:AddAsset(player, lod, "morphhead", "${MorphFile(?)}", priority, temporary)
	gr:AddAsset(player, lod, "easwmorph", "${EASWMorphFile(?)}")
	
	local part = "jersey"
	gr:CreateMaterialFromAttribulator(player, lod, part, "jersey_material", "${AttribMaterial('jersey')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "jersey_tex", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "kittex_common", "jersey_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "jerseyam", "jersey_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "jerseybnm", "jersey_nm")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShirt_Tens", "kitnumbers", "${db.player[?].kitNumberTens}.Raster")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShirt_Units", "kitnumbers", "${db.player[?].kitNumberUnits}.Raster")
	gr:SetTexture(player, lod, part, "textures", "tex_decalmap", "cresttex", "${db.player[?].crestTexName}")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "jerseyName", "namestamp${?}")
	
	gr:SetHotSpot(player, lod, part, "global", "jersey_decalBounds", "kithotspots", "jersey", "team")
	gr:SetHotSpot(player, lod, part, "global", "jersey_nameBound", "kithotspots", "jersey", "name")
	gr:SetHotSpot(player, lod, part, "global", "jersey_nameArcCenter", "kithotspots", "jersey", "name_arccenter")
		
	gr:SetConstantInt(player, lod, part, "global", "jersey_nameLayout", "${db.player[?].jerseyNameLayout}")
	
	gr:SetConstantARGB(player, lod, part, "global", "jersey_nameColor", "${db.player[?].kitNameColor}")

	skinTone = "${GetSkinTone(?,"..lod..")}"
	faceTone = "${GetFaceTone(?,"..lod..")}"
	
	part = "arms"
	gr:CreateMaterialFromAttribulator(player, lod, part, "head_material",  skinTone)
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "skintex", "body_${db.player[?].bodySkinToneType}_cm.Raster")  
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "normalMap", "bodycmn", "body_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "bodycmn", "body_coeff")
	gr:SetConstantARGB(player, lod, part, "global", "skincolor", "${db.player[?].playerBodySkinColor}")

	part = "legs"
	gr:CreateMaterialFromAttribulator(player, lod, part, "head_material", skinTone )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "skintex", "body_${db.player[?].bodySkinToneType}_cm.Raster")	
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "normalMap", "bodycmn", "body_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "bodycmn", "body_coeff")
	gr:SetConstantARGB(player, lod, part, "global", "skincolor", "${db.player[?].playerBodySkinColor}")

	part = "shorts"
	gr:CreateMaterialFromAttribulator(player, lod, part, "shorts_material", "${AttribMaterial('shorts')}") 
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shortstex", "shorts_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "shortstex", "shorts_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "shortsam", "shorts_am")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "shortsbnm", "shorts_nm")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "tex_decalmap", "cresttex", "${db.player[?].crestTexName}")	
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShorts_Tens", "shortsnumbers", "${db.player[?].kitNumberTens}.Raster")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShorts_Units", "shortsnumbers", "${db.player[?].kitNumberUnits}.Raster")
	gr:SetHotSpot(player, lod, part, "global", "shorts_decalBounds", "shortshotspots", "shorts", "team")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourShortPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourShortSec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourShortTer}")

	-- head
	part = "head"
	gr:CreateMaterialFromAttribulator(player, lod, part, "head_material", faceTone )
	gr:SetSubMesh(player, lod, part, "head")
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "facetex", "head_")
	gr:SetTexture(player, lod, part, "textures", "normalMap", "headcmn", "head_0_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "headcmn", "head_coeff")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "headcmn", "head_nm_wkl.Raster")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMask", "headcmn", "head_nm_mask.Raster")

	-- Eyes
	part = "eyes"	 
	gr:CreateMaterialFromAttribulator(player, lod, part, "eye_material", "${AttribMaterial('eyes')}" )
	gr:SetSubMesh(player, lod, part, "eyes")
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "eyetex", "eyes_")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "headcmn", "eye_coeff")
	gr:SetTexture(player, lod, part, "textures", "normalMap", "headcmn", "eyes_nm")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "env_")

	-- hair1
	part = "hair1"
	gr:CreateMaterialFromAttribulator(player, lod, part, "hair_material", "${AttribMaterial('player_hair_kk_alphaA')}")
	gr:SetSubMesh(player, lod, part, "alphaA")
	gr:SetPriority(player, lod, part, 1)             -- haircap render before hair 2
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "hairtex", "hair_cm") 
	gr:SetTexture(player, lod, part, "textures", "specAlphaMap", "hairtex", "hair_coeff")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetConstantARGB(player, lod, part, "global", "hairColor", "${GetHairColorARGB(?)}")

	-- hair2
	part = "hair2"
	gr:CreateMaterialFromAttribulator(player, lod, part, "hair_material2", "${AttribMaterial('player_hair_kk_alphaB')}")
	gr:SetSubMesh(player, lod, part, "alphaB")
	gr:SetPriority(player, lod, part, 2)             -- strands render after hair 1
	gr:DisableSelfShadow(player, lod, part)          -- Don't render the hairstrands into the selfshadow.
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "hairtex", "hair_cm")
	gr:SetTexture(player, lod, part, "textures", "specAlphaMap", "hairtex", "hair_coeff")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetConstantARGB(player, lod, part, "global", "hairColor", "${GetHairColorARGB(?)}")

	-- socks
	part = "socks"
	gr:CreateMaterialFromAttribulator(player, lod, "socks", "socks_material", "${AttribMaterial('sock')}" )  
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shortstex", "shorts_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "shortstex", "shorts_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "shortsam", "shorts_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "sockbnmlod", "shorts_nm")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourSocksPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourSocksSec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourSocksTer}")

	-- shoes
	part = "shoes"
	gr:CreateMaterialFromAttribulator(player, lod, part, "shoe_material", "${AttribMaterial('shoe')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shoetex", "shoe_cm")	
	gr:SetTexture(player, lod, part, "textures", "normalMap", "shoetex2", "shoe_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "shoetex2", "shoe_coeff")	
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	
	--underarmor neck
	local part = "underneck"
	gr:CreateMaterialFromAttribulator(player, lod, part, "underneck_material", "${AttribMaterial('undergear')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "jersey_tex", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "kittex_common", "jersey_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "jerseyam", "jersey_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "jerseybnm", "jersey_nm")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourJerseyPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourJerseySec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourJerseyTer}")
	
	--underarmor sleeves
	local part = "underarms"
	gr:CreateMaterialFromAttribulator(player, lod, part, "underarms_material", "${AttribMaterial('undergear')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "jersey_tex", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "kittex_common", "jersey_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "jerseyam", "jersey_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "jerseybnm", "jersey_nm")
	
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourJerseyPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourJerseySec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourJerseyTer}")

	--undershorts
	local part = "undershorts"
	gr:CreateMaterialFromAttribulator(player, lod, part, "undershorts_material", "${AttribMaterial('undergear')}") 
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shortstex", "shorts_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "shortstex", "shorts_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "shortsam", "shorts_am")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "shortsbnm", "shorts_nm")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourShortPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourShortSec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourShortTer}")
	
end

---------------------------------------------------------------------------------------------------
function PlayerAssetLowLod(player, lod)
	local gr = gRenderables

	skinLodTone = "${GetSkinTone(?,"..lod..")}"
	faceLodTone = "${GetFaceTone(?,"..lod..")}"


	-- GEO's
	if (lod == 1) then
		gr:AddAsset(player, lod, "jersey", "data/sceneassets/body/jerseylod_${db.player[?].jerseySleeveLength}_${db.player[?].jerseyTucked}_${db.player[?].jerseyArmBand}.rx3")
		gr:AddAsset(player, lod, "shorts", "data/sceneassets/body/shortslod_0_${db.player[?].shortstyle}.rx3")
		gr:AddAsset(player, lod, "bodyskinlod", "data/sceneassets/body/bodylod_${db.player[?].armLength}_0.rx3")
		gr:AddAsset(player, lod, "bodyshoelod", "data/sceneassets/body/shoeslod_0.rx3")
		gr:AddAsset(player, lod, "bodysocklod", "data/sceneassets/body/sockslod_0_${db.player[?].socklength}.rx3")
		gr:AddAsset(player, lod, "headlod",  "data/sceneassets/body/playerlod_head.rx3")
		gr:AddAsset(player, lod, "eyeslod",  "data/sceneassets/body/playerlod_head.rx3")
	elseif (lod == 2) then
		gr:AddAsset(player, lod, "jersey", "data/sceneassets/body/jerseylod_low_${db.player[?].jerseySleeveLength}_${db.player[?].jerseyTucked}_${db.player[?].jerseyArmBand}.rx3")
		gr:AddAsset(player, lod, "shorts", "data/sceneassets/body/shortslod_low_0_${db.player[?].shortstyle}.rx3")
		gr:AddAsset(player, lod, "bodyskinlod", "data/sceneassets/body/bodylod_low_${db.player[?].armLength}_0.rx3")
		gr:AddAsset(player, lod, "bodyshoelod", "data/sceneassets/body/shoeslod_low_0.rx3")
		gr:AddAsset(player, lod, "bodysocklod", "data/sceneassets/body/sockslod_low_0_${db.player[?].socklength}.rx3")
		gr:AddAsset(player, lod, "headlod",  "data/sceneassets/body/playerlod_head_low.rx3")
		gr:AddAsset(player, lod, "eyeslod",  "data/sceneassets/body/playerlod_head_low.rx3")
	end
	
	gr:AddAsset(player, lod, "hairlod",  "data/sceneassets/hairlod/hairlod_${db.player[?].hair}_${db.player[idx].faceProxyHeadClass}_0.rx3")
	gr:AddAsset(player, lod, "jerseybnmlod", "data/sceneassets/kit/jersey_${db.player[?].jerseyTucked}_bnm_lod.rx3")
	gr:AddAsset(player, lod, "shortsbnmlod", "data/sceneassets/kit/shorts_${db.player[?].shortstyle}_bnm_lod.rx3")

	local part = "jersey"
	gr:CreateMaterialFromAttribulator(player, lod, part, "jersey_material", "${AttribMaterial('jerseylod')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "jersey_tex", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "kittex_common", "jersey_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "jerseyam", "jersey_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "jerseybnmlod", "jersey_nm")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShirt_Tens", "kitnumbers", "${db.player[?].kitNumberTens}.Raster")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShirt_Units", "kitnumbers", "${db.player[?].kitNumberUnits}.Raster")
	gr:SetTexture(player, lod, part, "textures", "tex_decalmap", "cresttex", "${db.player[?].crestTexName}")
	gr:SetTextureFromRuntime(player, lod, part, "textures", "jerseyName", "namestamp${?}")
	
	gr:SetHotSpot(player, lod, part, "global", "jersey_decalBounds", "kithotspots", "jersey", "team")
	gr:SetHotSpot(player, lod, part, "global", "jersey_nameBound", "kithotspots", "jersey", "name")
	gr:SetHotSpot(player, lod, part, "global", "jersey_nameArcCenter", "kithotspots", "jersey", "name_arccenter")
	gr:SetConstantInt(player, lod, part, "global", "jersey_nameLayout", "${db.player[?].jerseyNameLayout}")
	
	gr:SetConstantARGB(player, lod, part, "global", "jersey_nameColor", "${db.player[?].kitNameColor}")

	part = "shorts"
	gr:CreateMaterialFromAttribulator(player, lod, part, "body_material", "${AttribMaterial('shortslod')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shortstex", "shorts_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "shortstex", "shorts_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "shortsam", "shorts_am")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "shortsbnmlod", "shorts_nm")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "tex_decalmap", "cresttex", "${db.player[?].crestTexName}")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShorts_Tens", "shortsnumbers", "${db.player[?].kitNumberTens}.Raster")
	gr:SetTexture(player, lod, part, "textures", "jerseyNumberShorts_Units", "shortsnumbers", "${db.player[?].kitNumberUnits}.Raster")
	gr:SetHotSpot(player, lod, part, "global", "shorts_decalBounds", "shortshotspots", "shorts", "team")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourShortPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourShortSec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourShortTer}")

	part = "bodyskinlod"
	gr:CreateMaterialFromAttribulator(player, lod, part, "body_material", skinLodTone )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "skintex", "body_${db.player[?].bodySkinToneType}_cm")  
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "normalMap", "bodycmn", "body_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "bodycmn", "body_coeff")
	gr:SetConstantARGB(player, lod, part, "global", "skincolor", "${db.player[?].playerBodySkinColor}")

	part = "bodyshoelod"
	gr:CreateMaterialFromAttribulator(player, lod, part, "body_material", "${AttribMaterial('shoelod')}" )
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shoetex", "shoe_cm")	
	gr:SetTexture(player, lod, part, "textures", "normalMap", "shoetex2", "shoe_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "shoetex2", "shoe_coeff")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")	

	part = "bodysocklod"
	gr:CreateMaterialFromAttribulator(player, lod, part, "body_material", "${AttribMaterial('socklod')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shortstex", "shorts_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "shortstex", "shorts_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "shortsam", "shorts_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "shortsbnmlod", "shorts_nm")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourSocksPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourSocksSec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourSocksTer}")

	-- eyes
	part = "eyeslod"
	gr:CreateMaterialFromAttribulator(player, lod, part, "head_material", "${AttribMaterial('eyeslod')}" )
	gr:SetSubMesh(player, lod, part, "eye")
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "eyetex", "eyes_")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "headcmn", "eye_coeff")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "env_")

	-- head
	part = "headlod"
	gr:CreateMaterialFromAttribulator(player, lod, part, "head_material", faceLodTone )
	gr:SetSubMesh(player, lod, part, "head")
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "facetex", "head_")
	gr:SetTexture(player, lod, part, "textures", "normalMap", "headcmn", "head_0_nm")
	gr:SetTexture(player, lod, part, "textures", "coeffMap", "headcmn", "head_coeff")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")

	-- hair
	part = "hairlod"
	gr:CreateMaterialFromAttribulator(player, lod, part, "hair_material", "${AttribMaterial('player_hair_kk_alphaA_lod')}")
	gr:SetSubMesh(player, lod, part, "alphaA")
	gr:SetPriority(player, lod, part, 1)
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "hairtex", "hair_cm")
	gr:SetTexture(player, lod, part, "textures", "specAlphaMap", "hairtex", "hair_coeff")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetConstantARGB(player, lod, part, "global", "hairColor", "${GetHairColorARGB(?)}")
	
	--underarmor neck
	local part = "underneck"
	gr:CreateMaterialFromAttribulator(player, lod, part, "underneck_material", "${AttribMaterial('socklod')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "jersey_tex", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "kittex_common", "jersey_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "jerseyam", "jersey_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "jerseybnmlod", "jersey_nm")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourJerseyPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourJerseySec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourJerseyTer}")

	--underarmor sleeves
	local part = "underarms"
	gr:CreateMaterialFromAttribulator(player, lod, part, "underarms_material", "${AttribMaterial('socklod')}" )
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "jersey_tex", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "kittex_common", "jersey_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "jerseyam", "jersey_am")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "jerseybnm", "jersey_nm")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourJerseyPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourJerseySec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourJerseyTer}")

	
	--undershorts
	local part = "undershorts"
	gr:CreateMaterialFromAttribulator(player, lod, part, "undershorts_material", "${AttribMaterial('socklod')}") 
	gr:SetTexture(player, lod, part, "textures", "diffuseTexture", "shortstex", "shorts_cm")
	gr:SetTexture(player, lod, part, "textures", "specularMap", "shortstex", "shorts_coeff")
	gr:SetTexture(player, lod, part, "textures", "occlusionMap", "shortsam", "shorts_am")
	gr:SetTexture(player, lod, part, "textures", "wrinkleMap", "shortsbnmlod", "shorts_nm")
	gr:SetTexture(player, lod, part, "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(player, lod, part, "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTexture(player, lod, part, "textures", "coverageMap", "coverage", "pitch")
	gr:SetTexture(player, lod, part, "textures", "weavePatternNormalMap", "cmnweave", "kit_weave")

	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorPri", "${db.player[?].kitColourShortPri}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorSec", "${db.player[?].kitColourShortSec}")
	gr:SetConstantARGB(player, lod, part, "global", "jerseyCustomColorTer", "${db.player[?].kitColourShortTer}")
	
end

---------------------------------------------------------------------------------------------------
function GetFaceTexTemplate(idx)
	if(db.player[idx].isVirtualPro == 1) then
		--return "data/sceneassets/faces/face_"..db.player[idx].faceType.."_"..db.player[idx].faceProxyHeadClass.."_0_"..db.player[idx].eyebrow.."_"..db.player[idx].faceSideBurn.."_"..db.player[idx].facialHairColor.."_"..db.player[idx].facialHairType.."_"..db.player[idx].headSkinType.."_"..db.player[idx].headSkinToneType.."_textures."..db.player[idx].faceTexExtension..";data/sceneassets/faces/face_"..db.player[idx].faceTypeFallback.."_"..db.player[idx].faceProxyHeadClass.."_0_"..db.player[idx].eyebrow.."_"..db.player[idx].faceSideBurnFallback.."_"..db.player[idx].facialHairColorFallback.."_"..db.player[idx].facialHairTypeFallback.."_"..db.player[idx].headSkinTypeFallback.."_"..db.player[idx].headSkinToneTypeFallback.."_textures.rx3"
		facetex = string.format("data/easw/head_%d.dds", db.player[idx].faceType)
		return facetex..";data/sceneassets/faces/face_"..db.player[idx].faceTypeFallback.."_"..db.player[idx].faceProxyHeadClass.."_0_"..db.player[idx].eyebrow.."_"..db.player[idx].faceSideBurnFallback.."_"..db.player[idx].facialHairColorFallback.."_"..db.player[idx].facialHairTypeFallback.."_"..db.player[idx].headSkinTypeFallback.."_"..db.player[idx].headSkinToneTypeFallback.."_textures.rx3"
	else
		return "data/sceneassets/faces/face_"..db.player[idx].faceType.."_"..db.player[idx].faceProxyHeadClass.."_0_"..db.player[idx].eyebrow.."_"..db.player[idx].faceSideBurn.."_"..db.player[idx].facialHairColor.."_"..db.player[idx].facialHairType.."_"..db.player[idx].headSkinType.."_"..db.player[idx].headSkinToneType.."_textures."..db.player[idx].faceTexExtension
	end
end

---------------------------------------------------------------------------------------------------
function GetJerseyBMN(idx)
	
	if(db.player[idx].forcePowerOfTwoBNM == 1) then
		return "data/sceneassets/kit/jersey_${db.player[?].jerseyTucked}_bnm_256x2.rx3"
	end
		
	if(db.player[idx].forceLowResBNM == 1 or db.player[idx].forcePowerOfTwoBNM == 1) then
		return "data/sceneassets/kit/jersey_${db.player[?].jerseyTucked}_bnm_256.rx3"			
	end
		
	return "data/sceneassets/kit/jersey_${db.player[?].jerseyTucked}_bnm.rx3"
end

---------------------------------------------------------------------------------------------------
function GetShortsBMN(idx)

	if(db.player[idx].forcePowerOfTwoBNM == 1) then
		return "data/sceneassets/kit/shorts_bnm_256x2.rx3"
	end

	if(db.player[idx].forceLowResBNM == 1) then
		return "data/sceneassets/kit/shorts_bnm_256.rx3"
	end
	
	return "data/sceneassets/kit/shorts_${db.player[idx].shortstyle}_bnm.rx3"
end

---------------------------------------------------------------------------------------------------
-- returns kit texture or goalie pants kit 5200
function GetShortsTex(idx)
	if(db.player[idx].shortstyle == 1) then
		return "data/sceneassets/kit/kit_5200_0_${db.player[?].shortstyleset}.rx3"
	else
		return "data/sceneassets/kit/kit_${db.player[?].kit}_${db.player[?].kitType}_${db.player[?].kitYear}.rx3"
	end
end

function GetKitTextureOperation(idx)
	if (db.player[idx].useTextureComposition == 1) then
		-- Creation Zone requires generated textures, describe the operation
		-- assetOperation generatetexture: "generatetexture texname width, height, mipCount, compression"
		return "generatetexture jersey_cm 1024,1024,9,eadxt1"
	else
		-- For others we do not need to generate the texture, so we just extract the source asset
		return "extracttexture jersey_cm"
	end
end

function GetKitTextureAssetName(idx)
	if (db.player[idx].useTextureComposition == 1) then
		-- Creation Zone requires generated textures, thus give the asset a unique name
		-- For CZ, kittype is always home, and year is always zero.
		return "gentex_kit_${db.player[?].kit}_${db.player[?].kitType}_${db.player[?].kitYear}_${db.player[?].teamside}_${db.player[?].kitColourJerseyPri}_${db.player[?].kitColourJerseySec}_${db.player[?].kitColourJerseyTer}"
	else
		-- Keep regular rx3 name as this is the source of the texture
		return "data/sceneassets/kit/kit_${db.player[?].kit}_${db.player[?].kitType}_${db.player[?].kitYear}.rx3"
	end
end


---------------------------------------------------------------------------------------------------
function PlayerAssetLod(player, lod)
	local gr = gRenderables
	
	local defaultpriority = 0	-- default priority

	gr:AddCallback(player, lod, "PlayerUpdate(?)")
	
	local kitTexAsset = "data/sceneassets/kit/kit_${db.player[?].kit}_${db.player[?].kitType}_${db.player[?].kitYear}.rx3"
	
	-- Generic files needed by all LODs
	gr:AddAsset(player, lod, "shader", "data/fifarna/shader.big")		
	gr:AddAsset(player, lod, "coverage", "data/sceneassets/pitch/pitchcovmap_${db.player[?].stadiumID}_${db.player[?].lightType}_textures.rx3")	
	gr:AddAsset(player, lod, "charcmn", "data/sceneassets/charactercmn/charactercmn_${db.player[?].lightType}.rx3")	
	gr:AddAsset(player, lod, "bodycmn", "data/sceneassets/body/body_common_textures.rx3")	
	gr:AddAsset(player, lod, "headcmn", "data/sceneassets/heads/head_common_textures.rx3")	

	-- Sponsor image for stamping onto kit
	gr:AddAsset(player, lod, "sponsortex", "data/ugc/cz_sponsor/${db.player[?].sponsorAssetId}.png;data/ugc/cz_sponsor/1.png", defaultpriority, ALLOCTYPE_TEMP_AUTO_RELEASE)
	
	-- gr:AddAssetEx(asset, lod, assetOperation, assetPart, containerName)
	-- extracttexture will create an asset with just the texture you extract from the source asset, this way we can free the original rx3, freeing unused textures.
	gr:AddAssetEx(player, lod, "extracttexture jersey_coeff", "kittex_common" , kitTexAsset)
	gr:AddAssetEx(player, lod, "extracttexture shorts_cm,shorts_coeff", "shortstex" , "${GetShortsTex(?)}")
	gr:AddAssetEx(player, lod, "extracthotspots", "kithotspots" , kitTexAsset)
	gr:AddAssetEx(player, lod, "extracthotspots", "shortshotspots",  "${GetShortsTex(?)}")
	gr:AddAssetEx(player, lod, "extracttexture ${db.player[?].crestTexName}", "cresttex", "${GetCrestAsset(?)}")
	

	-- Texture composition code
	-- Add the template asset as a temporary asset, auto releasing it when it's not being used (after texture generation in this case)
	gr:AddAssetEx(player, lod, "extracttexture jersey_cm", "kittex_cm_template" , kitTexAsset, defaultpriority, ALLOCTYPE_TEMP_AUTO_RELEASE)
	local part = "jersey_tex"
	-- GetKitTextureOperation will determine if texture composition is needed.
	gr:AddAssetEx(player, lod, "${GetKitTextureOperation(?)}", part , "${GetKitTextureAssetName(?)}")
	-- Describe texture composition in case we have to generate the texture, this material won't be created if no composition is needed.
	gr:CreateMaterial(player, lod, part, "texcomp.fx" )
	gr:SetTexture(player, lod, part, "textures", "texcomp_tex0", "kittex_cm_template", "jersey_cm")
	gr:SetTexture(player, lod, part, "textures", "texcomp_tex1", "sponsortex", "png")
	gr:SetConstantARGB(player, lod, part, "global", "recolorCustomColorPri", "${db.player[?].kitColourJerseyPri}")
	gr:SetConstantARGB(player, lod, part, "global", "recolorCustomColorSec", "${db.player[?].kitColourJerseySec}")
	gr:SetConstantARGB(player, lod, part, "global", "recolorCustomColorTer", "${db.player[?].kitColourJerseyTer}")
	gr:SetConstantARGB(player, lod, part, "global", "recolourMult", "${db.player[?].sponsorcolour}")
	gr:SetConstantHotSpot(player, lod, part, "global", "samplerBounds1", "${db.player[?].hotspotJerseySponsorL};${db.player[?].hotspotJerseySponsorT};${db.player[?].hotspotJerseySponsorR};${db.player[?].hotspotJerseySponsorB}")
	-- End of texture composition
	
	-- Set the jersey texture as a runtime texture so we can use it outside of player
	gr:SetRuntimeTexture(player, lod, "jersey_${db.player[?].kit}_${db.player[?].kitType}_${db.player[?].isgoalie}_${db.player[?].teamside}" , "jersey_tex", "jersey_cm")
	
	gr:AddAsset(player, lod, "shoetex", "data/sceneassets/shoe/shoe_${db.player[?].shoeType}_${db.player[?].shoeColor}_textures.rx3")	
	gr:AddAsset(player, lod, "shoetex2", "data/sceneassets/shoe/shoe_${db.player[?].shoeType}_textures.rx3")	
	gr:AddAsset(player, lod, "skintex", "data/sceneassets/body/skin_${db.player[?].bodySkinToneType}_textures.rx3")
	
	gr:AddAsset(player, lod, "hairtex", "data/sceneassets/hair/hair_${db.player[?].hair}_${db.player[?].faceProxyHeadClass}_textures.rx3")
	gr:AddAsset(player, lod, "shortsam", "data/sceneassets/kit/shorts_${db.player[?].shortstyle}_${db.player[?].wet}_textures.rx3")
	gr:AddAsset(player, lod, "jerseyam", "data/sceneassets/kit/jersey_${db.player[?].jerseyTucked}_${db.player[?].wet}_textures.rx3")
	local jerseyBNM = "${GetJerseyBMN(?)}"
	gr:AddAsset(player, lod, "jerseybnm", jerseyBNM)

	gr:AddAsset(player, lod, "cmnweave", "data/sceneassets/kit/kitweave.rx3")	
	local shortsBNM = "${GetShortsBMN(?)}"
	gr:AddAsset(player, lod, "shortsbnm", shortsBNM)
	
	-- Dirt masks not used in FIFARNA There is no runtime logic to drive them besides the expensiveness
	-- gr:AddAsset(player, lod, "shortsdk", "data/sceneassets/kit/shorts_dk.rx3")
	-- gr:AddAsset(player, lod, "jerseydk", "data/sceneassets/kit/jersey_dk.rx3")

	gr:AddAsset(player, lod, "eyetex", "data/sceneassets/heads/eyes_${db.player[?].eyeColor}_${db.player[?].faceProxyHeadClass}_textures.rx3")

	
	-- Add font as a temporary asset, because the font is used after the load (bind time), we still have to manually release it from the renderable
	-- TODO: add font stamping support to composite instead of having the renderable do this at bind time
	gr:AddAsset(player, lod, "font", "data/sceneassets/jerseyfonts/font_${db.player[?].kitNameFont}.ttf", defaultpriority, ALLOCTYPE_TEMP_MANUAL_RELEASE)
	gr:AddAsset(player, lod, "kitnumbers", "data/sceneassets/kitnumbers/kitnumbers_${db.player[?].kitNumberFont}_${db.player[?].kitNumberColor}.rx3;data/sceneassets/kitnumbers/kitnumbers_0_0.rx3")
	gr:AddAsset(player, lod, "shortsnumbers", "data/sceneassets/kitnumbers/kitnumbers_${db.player[?].shortsNumberFont}_${db.player[?].shortsNumberColor}.rx3;data/sceneassets/kitnumbers/kitnumbers_0_0.rx3")
	
	local faceGenTemplate = "${GetFaceTexTemplate(?)}"
	gr:AddAsset(player, lod, "facetex", faceGenTemplate)
	
	gr:AddAsset(player, lod, "underarms", "data/sceneassets/body/underarms_0_${db.player[?].underarms}.rx3")
	gr:AddAsset(player, lod, "underneck", "data/sceneassets/body/underneck_0_${db.player[?].underneck}.rx3")
	gr:AddAsset(player, lod, "undershorts", "data/sceneassets/body/undershorts_0_${db.player[?].undershorts}.rx3")


	if (lod == 0) then
		PlayerAssetHighLod(player, lod)
	elseif (lod == 1) then
		PlayerAssetLowLod(player, lod)	
	elseif (lod == 2) then
		PlayerAssetLowLod(player, lod)	
	elseif (lod == 3) then
		PlayerAssetShadow(player, lod)
	end	
	
end

---------------------------------------------------------------------------------------------------
function PlayerAssetBind(player)
	PlayerAssetLod(player, 0)
	PlayerAssetLod(player, 1)
	PlayerAssetLod(player, 2)
	PlayerAssetLod(player, 3)

end


tournamentRefereeKits = {}

function assignTournamentRefereeKits(tourn,id)
tournamentRefereeKits[tourn] = id
end

function getTournamentRefereeKits(tourn,id,home)

if (tournamentRefereeKits[tourn] ~= nil) then
return tournamentRefereeKits[tourn]
elseif ((tourn == -1) and (teamRefKits[home] ~= nil)) then

if (tournamentRefereeKits[teamRefKits[home]] ~= nil) then
return tournamentRefereeKits[teamRefKits[home]]
else
return id
end

else
return id
end

end


tournamentPlayerKits = {}
tournamentPlayerKitsNumber = {}
tournamentPlayerKitsName = {}

function assignTournamentPlayerKits(team,tourn,set,number,name)

if (tournamentPlayerKits[team] == nil) then
tournamentPlayerKits[team] = {}
tournamentPlayerKitsNumber[team] = {}
tournamentPlayerKitsName[team] = {}
end

-- if (tournamentPlayerKits[team][tourn] == nil) then
-- tournamentPlayerKits[team][tourn] = {}
-- end

tournamentPlayerKits[team][tourn] = set
tournamentPlayerKitsNumber[team][tourn] = number
tournamentPlayerKitsName[team][tourn] = name
end

function getTournamentPlayerKits(team,tourn,set)

if (tournamentPlayerKits[team] ~= nil) then
if (tournamentPlayerKits[team][tourn] ~= nil) then
return tournamentPlayerKits[team][tourn]
end
end

return set
end

function getTournamentPlayerKitsNumber(team,tourn,num)

if (tournamentPlayerKitsNumber[team][tourn] == -1) then
return num
end

return tournamentPlayerKitsNumber[team][tourn]
end

function getTournamentPlayerKitsName(team,tourn,name)
if (tournamentPlayerKitsName[team][tourn] == -1) then
return name
end

return tournamentPlayerKitsName[team][tourn]
end



playerBoot = {}

function assignPlayerBoot(id,boot)
playerBoot[id] = boot
end

function getPlayerBoot(id,boot)

if (globalBoot ~= -1) then
return globalBoot
end

if (playerBoot[id] ~= nil) then
return playerBoot[id]
else
return boot
end

end


gkPants = {}

function assignGKPants(id)
gkPants[id] = 1
end

function getGKPants(id,pant)

if (gkPants[id] ~= nil) then
return gkPants[id]
else
return pant
end

end


playerFace = {}

function assignPlayerFace(id)
playerFace[id] = 0
end

function getPlayerFace(id,headtype)

if (playerFace[id] ~= nil) then
return playerFace[id]
else
return headtype
end

end


gkKits = {}
gkKitsRandom = {}

function assignGKKit(team,player,gk)

if (gkKits[team] == nil) then
gkKits[team] = {}
end

gkKits[team][player] = gk
end

function assignRandomGKKit(team,player,gk)

if (gkKitsRandom[team] == nil) then
gkKitsRandom[team] = {}
end

gkKitsRandom[team][player] = gk
end

function getGKKit(team,player,home,away,gk)

-- if (matchGK[team] ~= nil) then
-- if (matchGK[team][home] ~= nil) then
-- if (matchGK[team][home][away] ~= nil) then
-- return matchGK[team][home][away]
-- end
-- end
-- end

if (matchKit[team] ~= nil) then
if (matchKit[team][home] ~= nil) then
if (matchKit[team][home][away] ~= nil) then
if (matchKit[team][home][away][gk] ~= nil) then
return matchKit[team][home][away][gk]
end
end
end
end


if (gkKitsRandom[team] ~= nil) then
if (gkKitsRandom[team][player] ~= nil) then
local count = #gkKitsRandom[team][player]
count = (home + away) % count
return gkKitsRandom[team][player][count+1]
end
end

if (gkKits[team] ~= nil) then
if (gkKits[team][player] ~= nil) then
return gkKits[team][player]
end
end

return gk
end


kitCollar = {}
kitNumberSet = {}
kitNumberColourShirt = {}
kitNumberColourShort = {}
kitNameFont = {}
kitNameColour = {}


function assignKitDetails(team,kit,namefont,namecolour,numberset,numbercolourshirt,numbercolourshort,collar)

if (kitCollar[team] == nil) then
kitCollar[team] = {}
end

if (kitNumberSet[team] == nil) then
kitNumberSet[team] = {}
end

if (kitNumberColourShirt[team] == nil) then
kitNumberColourShirt[team] = {}
end

if (kitNumberColourShort[team] == nil) then
kitNumberColourShort[team] = {}
end

if (kitNameFont[team] == nil) then
kitNameFont[team] = {}
end

if (kitNameColour[team] == nil) then
kitNameColour[team] = {}
end

kitCollar[team][kit] = collar
kitNumberSet[team][kit] = numberset
kitNumberColourShirt[team][kit] = numbercolourshirt
kitNumberColourShort[team][kit] = numbercolourshort
kitNameFont[team][kit] = namefont
kitNameColour[team][kit] = namecolour
end


kitCollarTournament = {}
kitNumberSetTournament = {}
kitNumberColourShirtTournament = {}
kitNumberColourShortTournament = {}
kitNameFontTournament = {}
kitNameColourTournament = {}



function assignTournamentKitDetails(team,kit,tournament,namefont,namecolour,numberset,numbercolourshirt,numbercolourshort,collar)

if (kitCollarTournament[team] == nil) then
kitCollarTournament[team] = {}
kitNumberSetTournament[team] = {}
kitNumberColourShirtTournament[team] = {}
kitNumberColourShortTournament[team] = {}
kitNameFontTournament[team] = {}
kitNameColourTournament[team] = {}
end

if (kitCollarTournament[team][kit] == nil) then
kitCollarTournament[team][kit] = {}
kitNumberSetTournament[team][kit] = {}
kitNumberColourShirtTournament[team][kit] = {}
kitNumberColourShortTournament[team][kit] = {}
kitNameFontTournament[team][kit] = {}
kitNameColourTournament[team][kit] = {}
end

kitCollarTournament[team][kit][tournament] = collar
kitNumberSetTournament[team][kit][tournament] = numberset
kitNumberColourShirtTournament[team][kit][tournament] = numbercolourshirt
kitNumberColourShortTournament[team][kit][tournament] = numbercolourshort
kitNameFontTournament[team][kit][tournament] = namefont
kitNameColourTournament[team][kit][tournament] = namecolour
end


function getKitCollar(team,kit,item,tournament)

if (kitCollarTournament[team] ~= nil) then
if (kitCollarTournament[team][kit] ~= nil) then
if ((kitCollarTournament[team][kit][tournament] ~= nil) and (kitCollarTournament[team][kit][tournament] ~= -1)) then
return kitCollarTournament[team][kit][tournament]
end
end
end


if (kitCollar[team] ~= nil) then
if ((kitCollar[team][kit] ~= nil) and (kitCollar[team][kit] ~= -1)) then
return kitCollar[team][kit]
end
end

return item
end

function getKitNumberSet(team,kit,item,tournament)

if (kitNumberSetTournament[team] ~= nil) then
if (kitNumberSetTournament[team][kit] ~= nil) then
if ((kitNumberSetTournament[team][kit][tournament] ~= nil) and (kitNumberSetTournament[team][kit][tournament] ~= -1)) then
return kitNumberSetTournament[team][kit][tournament]
end
end
end

if (kitNumberSet[team] ~= nil) then
if ((kitNumberSet[team][kit] ~= nil) and (kitNumberSet[team][kit] ~= -1)) then
return kitNumberSet[team][kit]
end
end

return item
end

function getKitNumberColourShirt(team,kit,item,tournament)

if (kitNumberColourShirtTournament[team] ~= nil) then
if (kitNumberColourShirtTournament[team][kit] ~= nil) then
if ((kitNumberColourShirtTournament[team][kit][tournament] ~= nil) and (kitNumberColourShirtTournament[team][kit][tournament] ~= -1)) then
return kitNumberColourShirtTournament[team][kit][tournament]
end
end
end

if (kitNumberColourShirt[team] ~= nil) then
if ((kitNumberColourShirt[team][kit] ~= nil) and (kitNumberColourShirt[team][kit] ~= -1)) then
return kitNumberColourShirt[team][kit]
end
end

return item
end

function getKitNumberColourShort(team,kit,item,tournament)

if (kitNumberColourShortTournament[team] ~= nil) then
if (kitNumberColourShortTournament[team][kit] ~= nil) then
if ((kitNumberColourShortTournament[team][kit][tournament] ~= nil) and (kitNumberColourShortTournament[team][kit][tournament] ~= -1)) then
return kitNumberColourShortTournament[team][kit][tournament]
end
end
end

if (kitNumberColourShort[team] ~= nil) then
if ((kitNumberColourShort[team][kit] ~= nil) and (kitNumberColourShort[team][kit] ~= -1)) then
return kitNumberColourShort[team][kit]
end
end

return item
end

function getKitNameFont(team,kit,item,tournament)

if (kitNameFontTournament[team] ~= nil) then
if (kitNameFontTournament[team][kit] ~= nil) then
if ((kitNameFontTournament[team][kit][tournament] ~= nil) and (kitNameFontTournament[team][kit][tournament] ~= -1)) then
return kitNameFontTournament[team][kit][tournament]
end
end
end

if (kitNameFont[team] ~= nil) then
if ((kitNameFont[team][kit] ~= nil) and (kitNameFont[team][kit] ~= -1)) then
return kitNameFont[team][kit]
end
end

return item
end

function getKitNameColour(team,kit,item,tournament)

if (kitNameColourTournament[team] ~= nil) then
if (kitNameColourTournament[team][kit] ~= nil) then
if ((kitNameColourTournament[team][kit][tournament] ~= nil) and (kitNameColourTournament[team][kit][tournament] ~= -1)) then
return kitNameColourTournament[team][kit][tournament]
end
end
end

if (kitNameColour[team] ~= nil) then
if ((kitNameColour[team][kit] ~= nil) and (kitNameColour[team][kit] ~= -1)) then
return kitNameColour[team][kit]
end
end

return item
end



playerSkinTone = {}

function assignPlayerSkinTone(player,tone)
playerSkinTone[player] = tone
end

function getPlayerPlayerSkinTone(player,tone)

if (playerSkinTone[player] ~= nil) then
return playerSkinTone[player]
else
return tone
end

end


arenaModePlayerKitTeam = -1
arenaModePlayerKitType = -1

arenaModeGKKitTeam = -1
arenaModeGKKitType = -1

function setArenaModePlayerKit(team,ktype)
arenaModePlayerKitTeam = team
arenaModePlayerKitType = ktype
end

function setArenaModeGKKit(team,ktype)
arenaModeGKKitTeam = team
arenaModeGKKitType = ktype
end


specificGKKit = {}

function assignSpecificGKKit(id)
specificGKKit[id] = 1
end

function getSpecificGKKit(id,gen)

if (specificGKKit[id] ~= nil) then
return id
else
return gen
end

end


teamRefKits = {}

function initRefKits()

refLeagueID1 = {269,270,271,272,819,820,826,1446,1447,1516,1788,15001}
refLeagueID4 = {229,231,232,239,673,674,675,680,681,1747,1750,2007,15005,100081,100087,110724}
refLeagueID7 = {383,517,567,568,569,598,1035,1041,1043,1048,1053,1598,1629,111044,111045,112119,120539,120540,120541,120542}
refLeagueID10 = {245,246,247,635,650,1902,1903,1904,1905,1906,1908,1909,1910,1913,1915,1971,100634,100651}
refLeagueID13 = {1,2,3,4,5,7,9,10,11,13,15,18,106,109,110,144,1792,1806,1917,1960}
refLeagueID14 = {8,12,14,17,19,88,91,94,95,97,142,1790,1793,1795,1796,1799,1800,1808,1919,1926,1932,1938,1952,1961}
refLeagueID16 = {57,59,65,66,70,72,73,74,210,217,219,226,378,614,1809,1819,1823,110456,110569,111271}
refLeagueID17 = {58,62,64,68,69,71,212,294,379,613,1530,1738,1739,1814,1815,1816,1820,110326,111376,111989}
refLeagueID19 = {21,22,23,25,28,29,31,32,34,36,38,166,169,171,175,485,10029,100409}
refLeagueID20 = {27,33,160,162,165,503,506,1824,1825,1826,1831,1832,10030,110329,110500,110596,110636,111239}
refLeagueID31 = {39,44,45,46,47,48,50,52,55,189,192,347,1838,1842,1843,110364,110374,110556,110915,112225}
refLeagueID32 = {54,190,200,203,206,1744,1746,1837,1844,1846,1847,1848,2044,110734,110912,111491,111974,111993,112124,112237,112281,112282}
refLeagueID39 = {687,688,689,691,693,694,695,696,697,698,101112,111065,111070,111140,111144,111651,111928,112134}
refLeagueID41 = {298,299,300,417,418,917,919,920,922,1456,1463,1465,1524,1755,2041,112199}
refLeagueID50 = {77,78,80,81,82,83,86,181,182,620,100804,100805}
refLeagueID53 = {240,241,243,244,448,449,452,453,456,457,459,461,479,480,481,483,573,1853,1860,110832}
refLeagueID54 = {242,450,462,468,472,477,571,1742,1855,1861,1867,15019,15021,100831,100851,100879,110062,110704,110833,110839,110902,111827}
refLeagueID56 = {319,320,321,432,433,700,702,703,705,710,711,1439,111277,111594,112072,112267}
refLeagueID60 = {89,143,346,361,1480,1794,1798,1801,1803,1807,1920,1924,1925,1933,1935,1937,1939,1941,1943,1945,1949,1955,1958,15048}
refLeagueID61 = {121,127,135,147,357,373,382,1797,1802,1804,1928,1929,1930,1934,1936,1946,1951,1954,1959,1962,15015,110313,110890,112259}
refLeagueID65 = {305,306,423,445,563,837,838,1571,1572,111132}
refLeagueID66 = {301,420,873,874,1570,1871,1873,110744,110745,110747,110749,111083,111085,111087,111091,111092}
refLeagueID67 = {312,315,100764,100765,100766,100767,100769,110089,110103,110109,110227,110231,110233,110234,112217,112218}
refLeagueID80 = {191,209,254,256,780,1785,2045,15011,111373,111821}
refLeagueID83 = {980,981,982,983,1473,1474,1475,1476,1477,1478,2055,2056,110765,111588,112115,112258}
refLeagueID189 = {322,324,435,894,896,897,900,1715,1862,110770}
refLeagueID308 = {234,236,237,665,744,1887,1888,1891,1892,1893,1895,1896,1897,1901,10019,111540}
refLeagueID341 = {1028,1032,1878,1879,1880,1881,1882,1970,101114,101116,110144,110147,110149,110150,110151,110152,110780,111678}
refLeagueID351 = {111393,111395,111396,111397,111398,111399,111400,111766,112078,112224}

for i=1,#refLeagueID1 do
teamRefKits[refLeagueID1[i]] = 1
end

for i=1,#refLeagueID4 do
teamRefKits[refLeagueID4[i]] = 4
end

for i=1,#refLeagueID7 do
teamRefKits[refLeagueID7[i]] = 7
end

for i=1,#refLeagueID10 do
teamRefKits[refLeagueID10[i]] = 10
end

for i=1,#refLeagueID13 do
teamRefKits[refLeagueID13[i]] = 13
end

for i=1,#refLeagueID14 do
teamRefKits[refLeagueID14[i]] = 14
end

for i=1,#refLeagueID16 do
teamRefKits[refLeagueID16[i]] = 16
end

for i=1,#refLeagueID17 do
teamRefKits[refLeagueID17[i]] = 17
end

for i=1,#refLeagueID19 do
teamRefKits[refLeagueID19[i]] = 19
end

for i=1,#refLeagueID20 do
teamRefKits[refLeagueID20[i]] = 20
end

for i=1,#refLeagueID31 do
teamRefKits[refLeagueID31[i]] = 31
end

for i=1,#refLeagueID32 do
teamRefKits[refLeagueID32[i]] = 32
end

for i=1,#refLeagueID39 do
teamRefKits[refLeagueID39[i]] = 39
end

for i=1,#refLeagueID41 do
teamRefKits[refLeagueID41[i]] = 41
end

for i=1,#refLeagueID50 do
teamRefKits[refLeagueID50[i]] = 50
end

for i=1,#refLeagueID53 do
teamRefKits[refLeagueID53[i]] = 53
end

for i=1,#refLeagueID54 do
teamRefKits[refLeagueID54[i]] = 54
end

for i=1,#refLeagueID56 do
teamRefKits[refLeagueID56[i]] = 56
end

for i=1,#refLeagueID60 do
teamRefKits[refLeagueID60[i]] = 60
end

for i=1,#refLeagueID61 do
teamRefKits[refLeagueID61[i]] = 61
end

for i=1,#refLeagueID65 do
teamRefKits[refLeagueID65[i]] = 65
end

for i=1,#refLeagueID66 do
teamRefKits[refLeagueID66[i]] = 66
end

for i=1,#refLeagueID67 do
teamRefKits[refLeagueID67[i]] = 67
end

for i=1,#refLeagueID80 do
teamRefKits[refLeagueID80[i]] = 80
end

for i=1,#refLeagueID83 do
teamRefKits[refLeagueID83[i]] = 83
end

for i=1,#refLeagueID189 do
teamRefKits[refLeagueID189[i]] = 189
end

for i=1,#refLeagueID308 do
teamRefKits[refLeagueID308[i]] = 308
end

for i=1,#refLeagueID341 do
teamRefKits[refLeagueID341[i]] = 341
end

for i=1,#refLeagueID351 do
teamRefKits[refLeagueID351[i]] = 351
end

end

frTourn = -1

function useTournamentGraphicsInFriendly(id)
frTourn = id
end

function getTournamentGraphics(id)
if (id == -1) then
return frTourn
end

return id
end


customGKPants = {}

function assignTeamGKPants(team,set)
customGKPants[team] = set
end

function getTeamGKPants(player,set)

if (customGKPants[player] ~= nil) then
return customGKPants[player]
else
return set
end

end

globalBoot = -1

function useGlobalBoot(boot)
globalBoot = boot
end


-- matchGK = {}

-- function assignGameGKKit(team,home,away,gk)

-- if (matchGK[team] == nil) then
-- matchGK[team] = {}
-- end

-- if (matchGK[team][home] == nil) then
-- matchGK[team][home] = {}
-- end

-- matchGK[team][home][away] = gk
-- end


function assignRandomPlayerBoot(id,boot)
local count = #boot
playerBoot[id] = boot[math.random(count)]
end


kitNameCurve = {}
--kitNameCase = {}

kitNameCurveTournament = {}




function assignKitNameLayout(team,kit,lay)

if (kitNameCurve[team] == nil) then
kitNameCurve[team] = {}
end

kitNameCurve[team][kit] = lay
end

nameLayout = {}

function assignTournamentNameLayout(team,tourn,lay)

if (nameLayout[team] == nil) then
nameLayout[team] = {}
end

nameLayout[team][tourn] = lay
end

function getKitNameCurve(team,kit,lay,tourn)

if (nameLayout[team] ~= nil) then
if (nameLayout[team][tourn] ~= nil) then
return nameLayout[team][tourn]
end
end

if (kitNameCurve[team] ~= nil) then
if (kitNameCurve[team][kit] ~= nil) then
return kitNameCurve[team][kit]
end
end

return lay

end


jerseyTuck = {}

function setJerseyTuck(player,tuck)
jerseyTuck[player] = tuck
end

function getJerseyTuck(player,tuck)

if (jerseyTuck[player] ~= nil) then
return jerseyTuck[player]
end

return tuck
end


sockHeight = {}

function setSockHeight(player,sock)
sockHeight[player] = sock
end

function getSockHeight(player,sock)

if (sockHeight[player] ~= nil) then
return sockHeight[player]
end

return sock
end


weatherAcc = {}
weatherAcc[0] = 0
weatherAcc[1] = 1
weatherAcc[2] = 1

function setWinterAccessoriesWeather(weather,option)
weatherAcc[weather] = option
end

function getWinterAccessoriesWeather(weather)

if (weatherAcc[weather] ~= nil) then
return (weatherAcc[weather] == 1)
end

return true
end


winterAccessories = {}

function assignWinterAccessories(player,option)
winterAccessories[player] = option
end

function getWinterAccessories(player,option)

if (winterAccessories[player] ~= nil) then
return winterAccessories[player]
end

return option
end


sleeveLength = {}

function setSleeveLength(player,option)
sleeveLength[player] = option
end

function getSleeveLength(player,option)

if (sleeveLength[player] ~= nil) then
return sleeveLength[player]
end

return option
end


matchKit = {}

function assignGameKit(team,home,away,type1,type2)

if (matchKit[team] == nil) then
matchKit[team] = {}
end

if (matchKit[team][home] == nil) then
matchKit[team][home] = {}
end

if (matchKit[team][home][away] == nil) then
matchKit[team][home][away] = {}
end

matchKit[team][home][away][type1] = type2
end

function getGameKit(team,home,away,type1)

if (matchKit[team] ~= nil) then
if (matchKit[team][home] ~= nil) then
if (matchKit[team][home][away] ~= nil) then
if (matchKit[team][home][away][type1] ~= nil) then
return matchKit[team][home][away][type1]
end
end
end
end

return type1
end


--Revolution Mod V1.3
--Edited by scouser09